package com.gitee.attendance.controller;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class MainsiteErrorController implements ErrorController {
    private Logger logger = LoggerFactory.getLogger(MainsiteErrorController.class);

    
    @RequestMapping("/error")
    public String handleError(HttpServletRequest request) {
        String result ;

        Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
        if (statusCode == 401) {
            result = "redirect:/401.html";
        } else if (statusCode == 404) {
            result = "redirect:/404.html";
        } else if (statusCode == 403) {
            result = "redirect:/403.html";
        } else {
            result = "redirect:/500.html";
        }
        logger.info(result);
        return result;
    }

    @Override
    public String getErrorPath() {
        return "/error";
    }
}